$(document).ready(function(){
    var oYhid = $('#yhid');
    var oYhkl = $('#yhkl');
    var oRememberYhid = $('#rememberYhid');
    var oRememberYhkl = $('#rememberYhkl');
    var token = getCookie("token");
    if (token && token != "null") {
        if (getCookie("rememberYhkl") && getCookie("rememberYhkl") != "null") {
            oYhid.val(token.split('-')[0]);
            oYhkl.val(token.split('-')[1]);
        } else if (getCookie("rememberYhid") && getCookie("rememberYhid") != "null") {
            oYhid.val(token.split('-')[0])
        }
    }
    oRememberYhid.on('change',function() {
        oRememberYhid.val(oRememberYhid.is(":checked") ? "1" : "0");
    })
    oRememberYhkl.on('change',function() {
        oRememberYhkl.val(oRememberYhkl.is(":checked") ? "1" : "0");
    })
    $('#doLogin').bind('click', function () {
        var msg = verify($('form'));
        if (msg.length) {
            alert("请检查必填项：" + msg.join(","));
            return;
        }
        var loginJson = $("form").serializeJson();
        myAjax({
            url: "/login.do",
            data: loginJson,
            mySuccess: function (res) {
                if (res.code == 1) {
                    window.location.href = getRootPath() +  "/userList.do";
                } else {
                    $('#errorInfo').text(res.msg);
                }
            }
        })
    })
})